//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import { BasePageQuery } from '../semester/type'
import { NoticePageRes, NoticeParams } from './type'

// 项目用户相关的请求地址
enum Notice_API {
  POST_PUT_NOTICE_ACTIVE = '/teaching_system/notice/active/{id}',
  GET_NOTICE_PAGE = '/teaching_system/notice/more',
  POST_PUT_NOTICE_ONE = '/teaching_system/notice/one',
  DELETE_NOTICE_BYID = '/teaching_system/notice/one/{id}',
}

/**
 * 发布公示
 * @param {string} id
 * @returns
 */
export const reqPublishNotice = (id: number) =>
  request.post<any, AxiosResponse<any>>(
    Notice_API.POST_PUT_NOTICE_ACTIVE.replace('{id}', id.toString()),
  )

/**
 * 下架公示
 * @param {string} id
 * @returns
 */
export const reqCancelNotice = (id: number) =>
  request.put<any, AxiosResponse<any>>(
    Notice_API.POST_PUT_NOTICE_ACTIVE.replace('{id}', id.toString()),
  )

/**
 * 获取公示
 * @param {string} basePageQuery
 * @returns
 */
export const reqGetNoticePage = (params: BasePageQuery) =>
  request.get<any, AxiosResponse<NoticePageRes>>(
    Notice_API.GET_NOTICE_PAGE + '?' + qs.stringify(params),
  )

/**
 * 添加公示
 * @param {object} params 新增公示表
 * @param {string} params.title 标题
 * @param {string} params.content 内容
 * @param {string} params.author 发布人
 * @param {number} params.type 接受人类型
 * @param {boolean} params.isActive 是否有效
 * @returns
 */
export const reqAddNotice = (params: NoticeParams) =>
  request.post<any, AxiosResponse<any>>(Notice_API.POST_PUT_NOTICE_ONE, params)

/**
 * 更新公示
 * @param {object} params 更新公示表
 * @param {number} params.noticeId 公告ID
 * @param {string} params.title 标题
 * @param {string} params.content 内容
 * @param {string} params.author 发布人
 * @param {number} params.type 接受人类型
 * @param {boolean} params.isActive 是否有效
 * @returns
 */
export const reqUpdateNotice = (params: NoticeParams) =>
  request.put<any, AxiosResponse<any>>(Notice_API.POST_PUT_NOTICE_ONE, params)

/**
 * 删除公示
 * @param {string} id
 * @returns
 */
export const reqDeleteNoticeById = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    Notice_API.DELETE_NOTICE_BYID.replace('{id}', id.toString()),
  )
